package com.chrray.position.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.beust.jcommander.internal.Lists;
import com.chrray.position.domain.dto.FdJobIntentionsDTO;
import com.chrray.position.enums.YesNoEnum;
import com.chrray.position.enums.app.FdJobTermEnum;
import com.chrray.position.enums.app.FdSalaryRangeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.List;

/**
 * 雇工求职意向表 对象
 *
 * @author wusiwee
 * @email wusiwee@163.com
 * @since 1.0.1 2024-08-07
 */

@Data
@ApiModel(description = "雇工求职意向表")
@TableName("fd_job_intentions")
public class FdJobIntentions extends Model<FdJobIntentions> {
	@ApiModelProperty(value = "主键")
	@TableId(type = IdType.AUTO)
	private Long id;

	@ApiModelProperty(value = "关联用户id")
	private Long userId;

	@ApiModelProperty(value = "求职类型: 1-短期,2-长期,3-都可以")
	private FdJobTermEnum jobType;


	@ApiModelProperty(value = "期望城市的行政区划编码")
	private String expectedCityCode;

	@ApiModelProperty(value = "期望城市的名称")
	private String expectedCityName;

	@ApiModelProperty(value = "常用地址")
	private String commonAddress;

	@ApiModelProperty(value = "期望薪资开始,元")
	private Integer expectedSalaryStart;

	@ApiModelProperty(value = "期望薪资结束,元")
	private Integer expectedSalaryEnd;

	@ApiModelProperty(value = "期望薪资: 1-面议,2-1000元以下,3-1000-2000元,4-2000-3000元,5-3000-5000元,6-5000-8000元,7-8000-12000元,8-12000-20000元,9-20000-25000元,10-25000元以上")
	private Integer expectedSalary;

	@ApiModelProperty(value = "创建时间")
	private Date createTime;

	private Integer delFlag;

	@TableField(exist = false)
    private  List<FdUserPositionRel> fdUserPositionRelList;

	public static FdJobIntentions findOneByUserId(Long userId) {
		LambdaQueryWrapper<FdJobIntentions> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(FdJobIntentions::getUserId, userId);
		return new FdJobIntentions().selectOne(queryWrapper);
	}

	public static FdJobIntentions findOneById(Long id) {
		return new FdJobIntentions().selectById(id);
	}

	public static FdJobIntentionsDTO findOneByUserIdOrDefault(Long userId) {
		FdJobIntentions intentions = findOneByUserId(userId);
		FdJobIntentionsDTO dto = new FdJobIntentionsDTO();
		List<Long> positionIds = Lists.newArrayList();
		List<String> positionNames = Lists.newArrayList();
		if (intentions != null) {
			List<FdUserPositionRel> rel = FdUserPositionRel.findAllByUserId(userId);
			for (FdUserPositionRel item : rel) {
				positionIds.add(item.getPositionId());
				positionNames.add(item.getPositionName());
			}
			BeanUtils.copyProperties(intentions, dto);
		}
		dto.setExpectedPosition(positionIds);
		dto.setExpectedPositionNames(positionNames);
		return dto;
	}
}
